package com.shadow.bus.main.alarm;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.shadow.bus.adapter.AlarmAdapter;
import com.shadow.bus.entity.AlarmInfoEntity;
import com.tepth.shadow.ui.recycler.BaseDecoration;
import com.zhangyu.shadow.core.delegate.ShadowDelegate;

import java.util.ArrayList;

import busfix.tepth.com.shadow_bus.R;
import busfix.tepth.com.shadow_bus.R2;
import butterknife.BindView;

/**
 * @author zhangyu
 * @date 2018/7/11
 */

public class TabFragment extends ShadowDelegate {
    private static final String ALARM_INFO = "list";

    public static TabFragment newInstance(ArrayList<AlarmInfoEntity> alarmInfo) {
        Bundle arguments = new Bundle();
        arguments.putSerializable(ALARM_INFO, alarmInfo);
        TabFragment fragment = new TabFragment();
        fragment.setArguments(arguments);
        return fragment;
    }

    @BindView(R2.id.recycler_view)
    RecyclerView mRecyclerView;
    AlarmAdapter mAlarmAdapter;
    ArrayList<AlarmInfoEntity> mAlarmInfo;

    @SuppressWarnings("unchecked")
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle bundle = getArguments();
        if (bundle != null) {
            mAlarmInfo = (ArrayList<AlarmInfoEntity>) bundle.getSerializable(ALARM_INFO);
        }
    }

    @Override
    public Object setLayout() {
        return R.layout.delegate_alarm_tab;
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, View rootView) {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mRecyclerView.addItemDecoration(BaseDecoration.create(getContext().getResources()
                .getColor(R.color.color_white), 1));
        mAlarmAdapter = new AlarmAdapter(getContext(), R.layout.item_alarm, mAlarmInfo);
        mRecyclerView.setAdapter(mAlarmAdapter);
    }
}
